home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 19 / macformat_19.iso / Shareware / Games / Star Flick / CT / Source / Menus.c < prev    next >
Text File  |  1994-02-07  |  3KB  |  132 lines

  1. /************************************************************************************
  2.  * Menus.c
  3.  *
  4.  *    Routines for CheeseToast menus.
  5.  *
  6.  * Menus are unused in this game, except in Attract Mode
  7.  ************************************************************************************/
  8. #include "ObjectWindow.h"
  9.  
  10. extern Boolean    gDoneFlag;
  11.  
  12. // Menu Handles
  13. MenuHandle    gAppleMenu, gFileMenu, gEditMenu;
  14.  
  15. #define MenuBaseID    128
  16.  
  17. // Menu Resource IDs
  18. enum    {
  19.     AppleMENU = 128, FileMENU, EditMENU
  20.     };
  21.  
  22. // Menu Item Numbers
  23. enum    {FM_Open = 1, FM_Close,    FM_Quit = 4};
  24. enum     {EM_Undo = 1, EM_Cut = 3, EM_Copy,
  25.          EM_Paste, EM_Clear};
  26.  
  27. // Menu Initialization code.
  28.  
  29. void MySetUpMenus(void)
  30. {
  31.     Handle    myMenuBar;
  32.     myMenuBar = GetNewMBar(MenuBaseID);
  33.     SetMenuBar(myMenuBar);
  34.  
  35.     gAppleMenu = GetMHandle(AppleMENU);
  36.     gFileMenu = GetMHandle(FileMENU);
  37.     gEditMenu = GetMHandle(EditMENU);
  38.  
  39.     AddResMenu(gAppleMenu, 'DRVR');
  40.  
  41.     DrawMenuBar();
  42. }
  43.  
  44.  
  45. //    Enable or disable the items in the Edit menu if a DA window
  46. //    comes up or goes away. Our application doesn't do anything with
  47. //    the Edit menu.
  48.  
  49. int MyEnableMenuItem (MenuHandle menu, short item, short ok);
  50.  
  51. void MyAdjustMenus(void)
  52. {
  53.     register WindowPeek wp;
  54.     short windowKind;
  55.     Boolean isDA,isObjectWindow;
  56.  
  57.     wp = (WindowPeek) FrontWindow();
  58.     windowKind = wp ? wp->windowKind : 0;
  59.     isDA = (windowKind < 0);
  60.     isObjectWindow = (wp->refCon == MyWindowID);
  61.  
  62.     MyEnableMenuItem(gEditMenu, EM_Undo, isDA);
  63.     MyEnableMenuItem(gEditMenu, EM_Cut, isDA);
  64.     MyEnableMenuItem(gEditMenu, EM_Copy, isDA);
  65.     MyEnableMenuItem(gEditMenu, EM_Paste, isDA);
  66.     MyEnableMenuItem(gEditMenu, EM_Clear, isDA);
  67.  
  68.     MyEnableMenuItem(gFileMenu, FM_Open, true);
  69.     MyEnableMenuItem(gFileMenu, FM_Close, isDA || isObjectWindow);
  70. }
  71.  
  72.  
  73. // Code to simplify enabling/disabling menu items.
  74. //
  75. static MyEnableMenuItem(MenuHandle menu, short item, short ok)
  76. {
  77.     if (ok)
  78.         EnableItem(menu, item);
  79.     else
  80.         DisableItem(menu, item);
  81.     if (item == 0)
  82.         DrawMenuBar();
  83. }
  84.  
  85.  
  86. //    Handle the menu selection. mSelect is what MenuSelect() and
  87. //    MenuKey() return: the high word is the menu ID, the low word
  88. //    is the menu item
  89. //
  90. void MyHandleMenu (long mSelect)
  91.  
  92. {
  93.     int            menuID = HiWord(mSelect);
  94.     int            menuItem = LoWord(mSelect);
  95.     Str255        name;
  96.     GrafPtr        savePort;
  97.     WindowPeek    frontWindow;
  98.     
  99.     switch (menuID) {
  100.     case AppleMENU:
  101.         GetPort(&savePort);
  102.         GetItem(gAppleMenu, menuItem, name);
  103.         OpenDeskAcc(name);
  104.         SetPort(savePort);
  105.         break;
  106.     
  107.     case FileMENU:
  108.         switch (menuItem) {
  109.           case FM_Close:
  110.             if ((frontWindow = (WindowPeek) FrontWindow()) == 0L)
  111.                 break;
  112.               
  113.             if (frontWindow->windowKind < 0)
  114.                  CloseDeskAcc(frontWindow->windowKind);
  115.             else if (frontWindow->refCon == MyWindowID)
  116.                 ((ObjectWindowPtr) frontWindow)->Dispose((WindowPtr) frontWindow);
  117.               break;
  118.  
  119.         case FM_Quit:
  120.             gDoneFlag = true;
  121.             break;
  122.         }
  123.         break;
  124.     case EditMENU:
  125.         if (!SystemEdit(menuItem-1))
  126.           SysBeep(5);
  127.         break;
  128.     }
  129.     HiliteMenu(0);
  130. }
  131.  
  132.